home *** CD-ROM | disk | FTP | other *** search
- {POWER FUNCTION GARY CURTIS NEWPORT
-
- PURPOSE : POWER raises x to the power y, where x, y are real numbers
- or real variables. Since y can be a fraction, POWER can
- be used to find roots, as well.
-
- ALGORITHM : See any algebra or calculus text for a discussion of
- logarithms and exponents.
-
- USE : Assume x has been declared as a real variable. To find the
- cube of 5,
-
- x := POWER(5.0,3.0);
-
- To find the cube root of 5,
-
- x := POWER(5.0,(1/3));
-
- To find the reciprocal of the cube root of 5,
-
- x := POWER(5.0,-(1/3));
-
- NOTE : If y is zero, POWER correctly returns a value of 1.0.
- (Any number raised to the zeroth power equals one.)
-
- Answers are APPROXIMATIONS; for example,
- the square root of four is 2.0000000029;
- two cubed is 7.9999999837.
-
-
- }
-
- function POWER (x, y : real) : real;
-
- VAR
- recip : boolean;
- temp : real;
-
- begin {POWER}
- if (y = 0) then
- POWER := 1.0
- else
- begin
- if (y < 0) then
- begin
- y := ABS(y);
- recip := true
- end {if}
- else
- recip := false;
- temp := EXP( y * LN(x));
- if recip then
- POWER := 1/temp
- else
- POWER := temp
- end {else}
- end; {POWER}
-